import {
  get
} from "./service"

const app = getApp()

function getUserInfo({
  success
}) {
  get(`${app.globalData.host}/user/info`, {}, {
    success: function (data) {
      console.info("------ getUserInfo ------", data)
      app.globalData.userInfo = data
      app.globalData.isFree = isFree()
      if (success) {
        success()
      }
    }
  })
}

function isFree() {
  const userInfo = app.globalData.userInfo
  if (!userInfo) return false
  const member = userInfo.member
  if (!member) return false
  if (member.expired) return false
  if (member.remainFreeNum < 1) return false
  return true
}

module.exports = {
  getUserInfo
}